package com.zxzb.dao;

import com.zxzb.entity.Yonghu;
import com.zxzb.util.JdbcUtil;

import java.util.List;

/**
 * 数据库交互-数据层
 */
public class YonghuDao {


    /**
     * 登录
     * @param obj
     * @return
     */
    public Yonghu login(List<Object> obj) {
        String sql="select * from yonghu where account=? and pwd=? and type=?";
        List<Yonghu> dto= JdbcUtil.executeQuery(sql, obj,Yonghu.class);
        if(dto!=null&&dto.size()>=1){
            return dto.get(0);
        }
        return null;
    }


    /**
     * 注册
     * @param obj
     * @return
     */
    public int register(List<Object> obj) {
        String sql="insert into yonghu(name,account,pwd,type) values(?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }


    /**
     * 验证数据库账号是否存在
     * @param objects
     * @return
     */
    public Yonghu exitAccount(List<Object> objects) {
        String sql="select * from yonghu where account=? and type=?";
        List<Yonghu> dto= JdbcUtil.executeQuery(sql, objects,Yonghu.class);
        if(dto!=null&&dto.size()>=1){
            return dto.get(0);
        }
        return null;
    }


}
